<template>
    <div>
        <h1>新增房间</h1>
        <tbody class="table">
        <tbody>
            <tr>
                <td>img</td>
                <td>
                    <input type="file" @change="upload">
                    <img style="height: 60px;width: 60px;" :src="axios.defaults.baseURL + data.Img">
                </td>
            </tr>
            <tr>
                <td>Uname</td>
                <td>
                    <input type="text" v-model="data.Uname">
                </td>
            </tr>
            <tr>
                <td>Age</td>
                <td>
                    <input type="text" v-model="data.Age">
                </td>
            </tr>
            <tr>
                <td>Pwd</td>
                <td>
                    <input type="Password" v-model="data.Pwd">
                </td>
            </tr>
            <tr>
                <td>身份证号</td>
                <td>
                    <input type="text" v-model="data.SFZH">
                </td>
            </tr>
             <tr>
                <td>注册时间</td>
                <td>
                    <input type="date" v-model="data.DateTime">
                </td>
            </tr>
            <tr>
                <td>Tid</td>
                <td>
                    <select v-model="data.Tid">
                        <option value="0">选择房型</option>
                        <option v-for="d in Bang" :value="d.Tid">{{ d.Tname }}</option>
                    </select>

                </td>
            </tr>
            <tr>
                <td>Stare</td>
                <td>
                    <input v-model="data.Stare" type="radio" name="Stare" value="1">启用
                    <input v-model="data.Stare" type="radio" name="Stare" value="2">禁用
                </td>
            </tr>
            <tr>
                <td>Set</td>
                <td>
                    <input v-model="data.Set" type="radio" name="Set" value="男">男
                    <input v-model="data.Set" type="radio" name="Set" value="女">女
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="button" class="btn btn-success" value="新增" @click="saveinfo">
                    <a href="/">返回会员列表</a>
                </td>
            </tr>
        </tbody>
        </tbody>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import {useRoute} from 'vue-router'
const router = useRouter()
const route = useRoute();


//上传
const upload = (abc: any) => {
    //取文件  创建表单数据对象 把文件保存到表单数据对象
    let f = abc.target.files[0]
    let fd = new FormData();
    fd.append("file", f);

    axios.post("/api/WJSC/UpLoad", fd).then(res => {
        data.value.Img = res.data;
    })
}
onMounted(() => {
    bang();
    Fantian(route.query.id);
})
const Fantian=(id:any)=>{
    axios.get("api/User/GetEmployeeById", { params: { id:route.query.id}}).then(res=>{
        console.log(res)
        data.value = res.data
    })
}
const bang = () => {
    axios.get("/api/User/bang").then(res => {
        Bang.value = res.data
    })

}
const Bang = ref([{
    "Tid": 0,
    "Tname": "string"
}])

const data = ref({
   "Uid": 0,
  "Uname": "郭富豪",
  "Pwd": "123456",
  "Set": "男",
  "Age": "21",
  "SFZH": "131127200210055256",
  "Img": "string",
  "Tid": 1,
  "Stare": 1,
  "IsDelete": false,
  "DateTime":""
})
const saveinfo = () => {
if(data.value.Uname=="")
{
    alert("姓名不能为空");
    return;
    
}
    axios.post('/api/User/UpdateEmployee', data.value).then(res => {
        if(res.data==-1){
            alert('用户名重复');
        }
        if (res.data > 0) {
            alert("修改成功")
            router.push("/showuser");
        }
        else {
            alert("修改失败...")
        }
    })
}
</script>

<style scoped></style>